﻿using Bll;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Web.Models;

namespace Web.Controllers
{
    public class EmployeeController : Controller
    {
        public ActionResult List()
        {
            BaseModel model = new BaseModel();
            return View(model);
        }

        [HttpPost]
        public string GetEmployee(string strWhere, int pageIndex)
        {
            var bll = new TableBll();
            string tblName = "Employee";
            Model_MakePages page = new Model_MakePages(tblName, strWhere, pageIndex);
            PageTable pageTable = bll.GetData_Page_FldsOrder(page);
            string str = Tool.SerializeObject(pageTable);

            return str;
        }

        public ActionResult Edit(int id = 0)
        {
            if (id == 0)
            {
                var model = new Employee();
                return View(model);
            }
            else
            {
                var model = new EmployeeBll().GetById(id);
                return View(model);
            }
        }

        [HttpPost]
        public ActionResult Edit(Employee model)
        {
            var bll = new EmployeeBll();
            if (bll.Add(model) > 0)
            {
                ViewBag.EditResult = "<script>alert('保存成功');document.location.href='List'</script>";
            }
            else
            {
                ViewBag.EditResult = "<script>alert('保存失败，请稍后重试！');</script>";
            }

            return View(model);
        }
    }
}
